"use strict";

const vm = require("node:vm");

const script = new vm.Script(/* js */ `
  function add(a, b) {
    return a + b;
  }
  
  const x = add(1, 2);
  console.log("add(1, 2) = " + x);
`);

const cacheWithoutAdd = script.createCachedData();
// In `cacheWithoutAdd` the function `add()` is marked for full compilation
// upon invocation.

script.runInThisContext();

const cacheWithAdd = script.createCachedData();
// `cacheWithAdd` contains fully compiled function `add()`.
